/**
 * ActivatorInfo.java
 */
package com.pluginsacceptor.acceptor.activator.model;

import java.util.Arrays;

/**
 * The class contains information about plugin
 */
public class PluginInfo {

    /** */
    private final String name;

    /** */
    private final String[] requirements;

    /** */
    private final Object activatorInstanse;

    /** */
    private final Class<?> activator;



    /**
     * Constructor
     * @param name is plug-in name
     * @param requirements the required plug-in name
     * @param plaginLocation the plug-in location in user interface  (panel, menu)
     * @param activator the class of activator
     * @throws IllegalAccessException if error has occurred
     * @throws InstantiationException if error has occurred
     */
    public PluginInfo(
        final String name,
        final String[] requirements,
        final Class<?> activator
    ) throws InstantiationException, IllegalAccessException {
        super();
        this.name = name;
        this.requirements = requirements;
        this.activator = activator;
        this.activatorInstanse = activator.newInstance();
    }


    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the requirements
     */
    public String[] getRequirements() {
        return requirements;
    }

    /**
     * @return the activator
     */
    public Class<?> getActivator() {
        return activator;
    }

    /**
     * @return the activatorInstanse
     */
    public Object getActivatorInstanse() {
        return activatorInstanse;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((this.activator == null) ? 0 : this.activator.hashCode());
        result = prime
                * result
                + ((this.activatorInstanse == null) ? 0
                        : this.activatorInstanse.hashCode());
        result = prime * result
                + ((this.name == null) ? 0 : this.name.hashCode());
        result = prime * result + Arrays.hashCode(this.requirements);
        return result;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PluginInfo other = (PluginInfo) obj;
        if (this.activator == null) {
            if (other.activator != null) {
                return false;
            }
        } else if (!this.activator.equals(other.activator)) {
            return false;
        }
        if (this.activatorInstanse == null) {
            if (other.activatorInstanse != null) {
                return false;
            }
        } else if (!this.activatorInstanse.equals(other.activatorInstanse)) {
            return false;
        }
        if (this.name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!this.name.equals(other.name)) {
            return false;
        }
        if (!Arrays.equals(this.requirements, other.requirements)) {
            return false;
        }
        return true;
    }


}
